package br.usp.ime.dojo.client;

import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.ClickListener;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Widget;

public class RoomInfo extends Composite {
	HorizontalPanel hPanel;
	VerticalPanel vPanel;
	Label name;
	Label createdBy;
	Label description;
	Label language;
	Button joinButton;
	JoinARoomListener joinARoomListener;
	
	public RoomInfo(final DojoRoomDTO dojoRoomDTO) {
		vPanel = new VerticalPanel();
		hPanel = new HorizontalPanel();
		name = new Label(dojoRoomDTO.getName());
		description = new Label(dojoRoomDTO.getDescription());
		joinButton = new Button("Join");
		createdBy = new Label("Created by: " + dojoRoomDTO.getCreator().getName());
		language = new Label("Language: " + dojoRoomDTO.getLanguage());
		
		vPanel.setHorizontalAlignment(VerticalPanel.ALIGN_CENTER);
		
		name.addStyleName("roomListingTitle");
		
		joinButton.addClickListener(new ClickListener(){

			public void onClick(Widget sender) {
				joinARoomListener.onJoinRequest(dojoRoomDTO);
			}			
		});
		
		name.setWidth("150px");
		description.setWidth("200px");
		joinButton.setWidth("30px");
		
		if(!dojoRoomDTO.isStarted())
			name.setStylePrimaryName("redfont");
		
		vPanel.add(name);
				
		//hPanel.add(imagem);
		hPanel.add(createdBy);
		vPanel.add(hPanel);
		
		vPanel.add(language);
		vPanel.add(description);
		
		vPanel.add(joinButton);
		
		vPanel.addStyleName("roomInfoBox");
		
		initWidget(vPanel);
	}

	public void setJoinRequestListener(JoinARoomListener listener) {
		joinARoomListener = listener;
	}

}
